/*    
 * Copyright (c) 2013 ISoftStone, Inc.
 * All right reserved.
 *
 * 文件名：      ISpecialAccountBookItemDao.java
 * 作者:     Jacky Wang
 * 创建日期： 2013-7-30 下午04:03:59
 * 版本：           
 *
 */
package com.isoftstone.industry.aaa.core.dao.assist;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.isoftstone.industry.persistance.bean.SpecialAccountBookItem;
import com.isoftstone.modules.core.persistence.IGenericDao;

/**
 *
 * @author jacky
 */
public interface SpecialAccountBookItemDao extends IGenericDao<SpecialAccountBookItem, String>
{
	@Query("select x from SpecialAccountBookItem x where x.accountBook.id=:acctBookId and x.source=:source and x.sourceId=:sourceId and x.type=:type and (x.effDate <= :date and x.expDate >= :date)")
	List<SpecialAccountBookItem> findBySourceAndTypeAndAcctBookAndDateBetween(@Param("sourceId")String sourceId, @Param("source")String source, @Param("type")String type, @Param("acctBookId")String acctBookId, @Param("date")Date date);
	
	@Query("select x from SpecialAccountBookItem x where x.accountBook.id=:acctBookId and x.source=:source and x.sourceId=:sourceId and x.type=:type")
	List<SpecialAccountBookItem> findBySourceAndTypeAndAcctBook(@Param("sourceId")String sourceId, @Param("source")String source, @Param("type")String type, @Param("acctBookId")String acctBookId);
	
	@Modifying
	@Query("update SpecialAccountBookItem x set x.balance=:balance, x.modifiedTime=:modifiedTime where x.id=:id")
	void updateBalance(@Param("id") String id, @Param("balance") double balance, @Param("modifiedTime") Timestamp modifiedTime);
	
	@Modifying
	@Query("update SpecialAccountBookItem x set x.balance=:balance, x.freezeBalance=:freezeBalance, x.modifiedTime=:modifiedTime where x.id=:id")
	void updateBalance(@Param("id") String id, @Param("balance") double balance, @Param("freezeBalance") double freezeBalance, @Param("modifiedTime") Timestamp modifiedTime);
}
